//
//  ViewController.swift
//  ZPlayer
//
//  Created by zuber on 2018/11/14.
//  Copyright © 2018年 zuber. All rights reserved.
//

import UIKit
import AVFoundation

class ViewController: UIViewController {
  
  let items: [String] = [
    "http://video.zuber.im/f84354f19b259800f95817a0/2018/11/15/5bed2ff2013ed_vformat.mp4" ,
    "http://video.zuber.im/852da13e86cfeec6732e66f4/2018/11/15/5bed24c523fc4_vformat.mp4" ,
    "http://video.zuber.im/1b64b553882d5c002b249db9/2018/11/15/5bed23f68b410_vformat.mp4" ,
    "http://video.zuber.im/72848c01f174fbf607855f8b/2018/11/15/5bed1be3094dd_vformat.mp4" ,
    "http://video.zuber.im/a0a4ec8d441a5992f874a035/2018/11/15/5bed1fb427265_vformat.mp4" ,
    "http://video.zuber.im/a0a4ec8d441a5992f874a035/2018/11/15/5bed1e2d25aba_vformat.mp4" ,
    "http://video.zuber.im/66c697c5b8372f21497ce5ce/2018/11/15/5bed1cd9912ec_vformat.mp4" ,
    "http://video.zuber.im/c270f83c507260336b8a4737/2018/11/15/5bed1ab11b808_vformat.mp4" ,
    "http://video.zuber.im/544f6a79d5f5cf758d87156d/2018/11/15/5bed1b40aa840_vformat.mp4" ,
    "http://video.zuber.im/60739b46407da142e373fee6/2018/11/15/5bed18802ec2c_vformat.mp4"
  ]
  
  
  @IBOutlet weak var tableView: UITableView!
  
  override func viewDidLoad() {
    super.viewDidLoad()
    tableView.rowHeight = 50
    tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
    tableView.delegate = self
    tableView.dataSource = self
  }
  
  
}

extension ViewController: UITableViewDelegate, UITableViewDataSource{
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
    cell.textLabel?.text = items[indexPath.row]
    return cell
  }
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return items.count
  }
  
  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)
    let playerController = ZPlayerController(items[indexPath.row])
    self.present(playerController, animated: true, completion: nil)
  }
  
}

